
import requests

#检测代理ip是否可用
url = 'http://basic.10jqka.com.cn/300001/equity.html'

def check(scraw_ip):
    ip_pass = []
    for ip in scraw_ip:
        ip = (ip[0] + ":" + ip[1])
        result = validateIp(ip)
        print(ip + " is " + str(result))
        if result == True:
            ip_pass.append(ip)
            print(ip + "==============================================is true")
    return ip_pass


def validateIp(proxy):  # 检测ip是否可用
    # proxy_temp = {"http": 'http:'+ proxy}
    proxy_temp = {"http": proxy}
    # print(proxy_temp)
    try:
        response = requests.get(url, proxies=proxy_temp, timeout=3)
        return True
    except Exception as e:
        print(str(e))
        return False

